package com.xinchuang.service.image.impl;

import com.xinchuang.comment.KeyWord;
import com.xinchuang.service.image.MercatorWmtsService;
import com.xinchuang.utils.DBUtils;
import com.xinchuang.utils.MercatorWmtsUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.File;

/**
 * TODO
 *
 * @author zkwczx
 * @version 1.0
 * @date 2023/9/21 17:20
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class MercatorWmtsServiceImpl implements MercatorWmtsService {

    private final KeyWord keyWord;

    @Override
    public byte[] getTile(Integer x, Integer y, Integer z, String id) {
        String quadKey = MercatorWmtsUtils.xyzToQuadKey(x, y, z);
        String dbPath = keyWord.getRootDir() + keyWord.getDbDir() + File.separator + id + ".idb";
        return DBUtils.get(dbPath, quadKey);
    }

}
